package com.ruoyi.tester.domain;

import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author SongJun
 * @description TODO:
 * @date 2022/4/15 14:10
 */
public class TaskInterfaceEffectiveInfo {
    private Long taskId;
    private String taskDesc;
    private Long loginConfigId;
    private Long relationId;
    private Long interfaceId;
    private String interfaceDesc;
    private String host;
    private Integer port;
    private String mapping;
    private String httpMethod;
    private String contentType;
    private String queryParam;
    private String bodyParam;
    private String pathParam;
    private String dependParam;
    private String judgeExpression;
    private List<Long> dependRelationIdList;
    private Long taskCallLogId;
    private String finalUrl;

    public TaskInterfaceEffectiveInfo(TaskInterfaceFullInfo fullInfo){
        setTaskId(fullInfo.getTaskId());
        setTaskDesc(fullInfo.getTaskDesc());
        setLoginConfigId(fullInfo.getRelationLoginConfigId() == null ? fullInfo.getTaskLoginConfigId() : fullInfo.getRelationLoginConfigId());
        setRelationId(fullInfo.getRelationId());
        setInterfaceId(fullInfo.getInterfaceId());
        setInterfaceDesc(fullInfo.getInterfaceDesc());
        setHost(StringUtils.hasLength(fullInfo.getRelationHost()) ? fullInfo.getRelationHost() : fullInfo.getTaskHost());
        setPort(fullInfo.getRelationPort() == null ? fullInfo.getTaskPort() : fullInfo.getRelationPort());
        setMapping(fullInfo.getMapping());
        setHttpMethod(fullInfo.getHttpMethod());
        setContentType(StringUtils.hasLength(fullInfo.getRelationContentType()) ? fullInfo.getRelationContentType() : fullInfo.getInterfaceContentType());
        setQueryParam(StringUtils.hasLength(fullInfo.getRelationQueryParam()) ? fullInfo.getRelationQueryParam() : fullInfo.getInterfaceQueryParam());
        setBodyParam(StringUtils.hasLength(fullInfo.getRelationBodyParam()) ? fullInfo.getRelationBodyParam() : fullInfo.getInterfaceBodyParam());
        setPathParam(StringUtils.hasLength(fullInfo.getRelationPathParam()) ? fullInfo.getRelationPathParam() : fullInfo.getInterfacePathParam());
        setJudgeExpression(fullInfo.getJudgeExpression());
        setDependParam(fullInfo.getDependParam());
        if(StringUtils.hasLength(fullInfo.getDependRelationIds())){
            String[] split = fullInfo.getDependRelationIds().split(",");
            List<Long> idList = Arrays.stream(split).map(x -> Long.valueOf(x.trim())).collect(Collectors.toList());
            setDependRelationIdList(idList);
        } else {
            setDependRelationIdList(Arrays.asList());
        }
    }

    public Long getTaskId() {
        return taskId;
    }

    public void setTaskId(Long taskId) {
        this.taskId = taskId;
    }

    public String getTaskDesc() {
        return taskDesc;
    }

    public void setTaskDesc(String taskDesc) {
        this.taskDesc = taskDesc;
    }

    public Long getLoginConfigId() {
        return loginConfigId;
    }

    public void setLoginConfigId(Long loginConfigId) {
        this.loginConfigId = loginConfigId;
    }

    public Long getRelationId() {
        return relationId;
    }

    public void setRelationId(Long relationId) {
        this.relationId = relationId;
    }

    public Long getInterfaceId() {
        return interfaceId;
    }

    public void setInterfaceId(Long interfaceId) {
        this.interfaceId = interfaceId;
    }

    public String getInterfaceDesc() {
        return interfaceDesc;
    }

    public void setInterfaceDesc(String interfaceDesc) {
        this.interfaceDesc = interfaceDesc;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getMapping() {
        return mapping;
    }

    public void setMapping(String mapping) {
        this.mapping = mapping;
    }

    public String getHttpMethod() {
        return httpMethod;
    }

    public void setHttpMethod(String httpMethod) {
        this.httpMethod = httpMethod;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getQueryParam() {
        return queryParam;
    }

    public void setQueryParam(String queryParam) {
        this.queryParam = queryParam;
    }

    public String getPathParam() {
        return pathParam;
    }

    public void setPathParam(String pathParam) {
        this.pathParam = pathParam;
    }

    public String getBodyParam() {
        return bodyParam;
    }

    public void setBodyParam(String bodyParam) {
        this.bodyParam = bodyParam;
    }

    public List<Long> getDependRelationIdList() {
        return dependRelationIdList;
    }

    public void setDependRelationIdList(List<Long> dependRelationIdList) {
        this.dependRelationIdList = dependRelationIdList;
    }

    public String getDependParam() {
        return dependParam;
    }

    public void setDependParam(String dependParam) {
        this.dependParam = dependParam;
    }

    public String getJudgeExpression() {
        return judgeExpression;
    }

    public void setJudgeExpression(String judgeExpression) {
        this.judgeExpression = judgeExpression;
    }

    public Long getTaskCallLogId() {
        return taskCallLogId;
    }

    public void setTaskCallLogId(Long taskCallLogId) {
        this.taskCallLogId = taskCallLogId;
    }

    public String getFinalUrl() {
        return finalUrl;
    }

    public void setFinalUrl(String finalUrl) {
        this.finalUrl = finalUrl;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("TaskInterfaceEffectiveInfo{");
        sb.append("taskId=").append(taskId);
        sb.append(", taskDesc='").append(taskDesc).append('\'');
        sb.append(", loginConfigId=").append(loginConfigId);
        sb.append(", relationId=").append(relationId);
        sb.append(", interfaceId=").append(interfaceId);
        sb.append(", interfaceDesc='").append(interfaceDesc).append('\'');
        sb.append(", host='").append(host).append('\'');
        sb.append(", port=").append(port);
        sb.append(", mapping='").append(mapping).append('\'');
        sb.append(", httpMethod='").append(httpMethod).append('\'');
        sb.append(", contentType='").append(contentType).append('\'');
        sb.append(", queryParam='").append(queryParam).append('\'');
        sb.append(", bodyParam='").append(bodyParam).append('\'');
        sb.append(", pathParam='").append(pathParam).append('\'');
        sb.append(", dependParam='").append(dependParam).append('\'');
        sb.append(", judgeExpression='").append(judgeExpression).append('\'');
        sb.append(", dependRelationIdList=").append(dependRelationIdList);
        sb.append(", taskCallLogId=").append(taskCallLogId);
        sb.append(", finalUrl='").append(finalUrl).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
